<div class="layui-fluid" lay-title="表单组合">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" lay-filter="form-group">
                <div class="layui-form-item">
                    <label class="layui-form-label">任务名</label>
                    <div class="layui-input-block">
                        <input type="text" name="jobName" lay-verify="required" autocomplete="off" placeholder="请输入任务名" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">任务组</label>
                    <div class="layui-input-block">
                        <input type="text" name="jobGroup" lay-verify="required" autocomplete="off" placeholder="请输入任务组" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">类名</label>
                    <div class="layui-input-block">
                        <input type="text" name="className" lay-verify="required" autocomplete="off" placeholder="请输入类名" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">表达式</label>
                    <div class="layui-input-block">
                        <input type="text" name="cronExpression" lay-verify="required" autocomplete="off" placeholder="请输入表达式" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="form-group-submit">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    layui.use(['jquery', 'admin', 'form', 'layer'], function () {
        var $ = layui.jquery
            , layer = layui.layer
            , form = layui.form
            , admin = layui.admin;
        var sysJob = {};
        var jobId = POPUP_DATA.id;
        var table = POPUP_DATA.table;

        form.render(null, 'form-group');
        //var id = POPUP_DATA.id;
        if (jobId) {
            // 初始化
            $.ajax({
                type: 'get',
                url: '/sysJob/info/' + jobId + '?token=' + admin.loginToken,
                dataType: 'json',
                success: function (data) {
                    sysJob = data.sysJob;
                    if (sysJob) {
                        form.val("form-group", {
                            "jobName": sysJob.jobName // "name": "value"
                            , "jobGroup": sysJob.jobGroup
                            , "className": sysJob.className
                            , "cronExpression": sysJob.cronExpression
                        });
                    }
                }
            });
        }
        /* 监听提交 */
        form.on('submit(form-group-submit)', function (data) {
            /*layer.alert(JSON.stringify(data.field), {
             title: '最终的提交信息'
             })*/
            var field = data.field;
            var jobData = {};
            jobData.status = sysJob.status;
            jobData.jobName = field.jobName;
            jobData.jobGroup = field.jobGroup;
            jobData.className = field.className;
            jobData.cronExpression = field.cronExpression;
            var url = "/sysJob/save";
            if (jobId) {
                url = "/sysJob/update?_method=PUT";
                jobData.id = jobId;
            }
            admin.post({
                url: url,
                contentType: "application/json",
                data: JSON.stringify(jobData),
                headers: {
                    "token": admin.loginToken
                },
                success: function (res) {
                    if (res.code == 0) {
                        // 提醒保存成功，关闭当前弹窗
                        layer.msg(res.msg);
                        layer.closeAll();
                        //刷新
                        table.reload('list-table-job', {
                            url: '/sysJob/page?token=' + admin.loginToken,
                            page: {
                                curr: 1
                            }
                        })
                    } else {
                        layer.msg(res.msg);
                    }
                }
            });
            return false;
        });
    });
</script>